package com.sskj.wallet.uitl;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.afollestad.materialdialogs.MaterialDialog;
import com.sskj.common.util.ClickUtil;
import com.sskj.lib.bean.CoinEnum;
import com.sskj.lib.util.ImageUtil;
import com.sskj.lib.util.QRCodeUtil;
import com.sskj.wallet.R;

public class TipWalletUtil {
    public static MaterialDialog showNoCameraTip(Context context, OnSure onSure) {
        MaterialDialog dialog = new MaterialDialog.Builder(context)
                .customView(R.layout.wallet_dialog_no_camera_tip, false)
                .autoDismiss(true)
                .cancelable(true)
                .show();
        View customView = dialog.getCustomView();

        ClickUtil.click(customView.findViewById(R.id.btCancel), () -> {
            dialog.dismiss();
        });
        ClickUtil.click(customView.findViewById(R.id.btSure), () -> {
            dialog.dismiss();
            onSure.onSure();

        });
        return dialog;
    }

    public static MaterialDialog showBackupSuccess(Context context,OnSure onSure) {
        MaterialDialog dialog = new MaterialDialog.Builder(context)
                .customView(R.layout.wallet_dialog_backup_success, false)
                .autoDismiss(true)
                .cancelable(true)
                .show();
        View customView = dialog.getCustomView();

        ClickUtil.click(customView.findViewById(R.id.btCancel), () -> {
            dialog.dismiss();
        });
        ClickUtil.click(customView.findViewById(R.id.btSure), () -> {
            dialog.dismiss();
            onSure.onSure();

        });
        return dialog;
    }

    public static MaterialDialog showQRCode(Context context, String text) {
        MaterialDialog dialog = new MaterialDialog.Builder(context)
                .customView(R.layout.wallet_dialog_qrcode, false)
                .autoDismiss(true)
                .cancelable(true)
                .show();
        View customView = dialog.getCustomView();
        ((ViewGroup) (customView.getParent())).setBackgroundColor(Color.TRANSPARENT);
        ((ViewGroup) (customView.getParent().getParent())).setBackgroundColor(Color.TRANSPARENT);
        ((ViewGroup) (customView.getParent().getParent().getParent())).setBackgroundColor(Color.TRANSPARENT);
        ((ViewGroup) (customView.getParent().getParent().getParent().getParent())).setBackgroundColor(Color.TRANSPARENT);
        ((ViewGroup) (customView.getParent().getParent().getParent().getParent().getParent())).setBackgroundColor(Color.TRANSPARENT);

        ImageView ivQRCode = customView.findViewById(R.id.ivQRCode);
        QRCodeUtil.createImage(text, 400, new QRCodeUtil.OnEncodeQRCodeCallback() {
            @Override
            public void onAnalyzeSuccess(Bitmap bitmap) {
                ivQRCode.setImageBitmap(bitmap);
            }

            @Override
            public void onAnalyzeFailed() {
            }
        });

        return dialog;
    }

    public static MaterialDialog showChoose(Context context, OnChoose onChoose) {
        MaterialDialog dialog = new MaterialDialog.Builder(context)
                .customView(R.layout.wallet_dialog_choose, false)
                .autoDismiss(true)
                .cancelable(true)
                .show();
        View customView = dialog.getCustomView();
        ((ViewGroup) (customView.getParent())).setBackgroundColor(Color.TRANSPARENT);
        ((ViewGroup) (customView.getParent().getParent())).setBackgroundColor(Color.TRANSPARENT);
        ((ViewGroup) (customView.getParent().getParent().getParent())).setBackgroundColor(Color.TRANSPARENT);
        ((ViewGroup) (customView.getParent().getParent().getParent().getParent())).setBackgroundColor(Color.TRANSPARENT);
        ((ViewGroup) (customView.getParent().getParent().getParent().getParent().getParent())).setBackgroundColor(Color.TRANSPARENT);

        TextView tvBTC = customView.findViewById(R.id.tvBTC);
        TextView tvETH = customView.findViewById(R.id.tvETH);
        ClickUtil.click(tvBTC, () -> {
            dialog.dismiss();
            onChoose.choose(CoinEnum.BTC);
        });
        ClickUtil.click(tvETH, () -> {
            dialog.dismiss();

            onChoose.choose(CoinEnum.ETH);

        });

        return dialog;
    }

    public interface OnChoose {
        void choose(CoinEnum coinEnum);
    }

    public interface OnSure {
        void onSure();
    }

}
